#!/bin/bash

dirPrefix="tmp"
nestDirFlag=0
parentsDir=''

read_dir(){
  for file in `ls $1`
  do
    path=$1"/"$file
    if [ -d $path ]
    then
      nestDirFlag=`expr $nestDirFlag + 1`
      if [ $nestDirFlag -gt 1 ]
      then
        newDir="$parentsDir"/"$file"
      else
        newDir=$file
      fi
      echo ">>> $dirPrefix"/"$newDir"
      parentsDir=$newDir
      mkdir -p "$dirPrefix"/"$parentsDir"
      read_dir $1"/"$file
    else
      nestDirFlag=0

      if [ "${file##*.}"x = "vhd"x ];then
        vhdlFileName="$dirPrefix"/"$newDir"/"$file"
        verilogFileName="${vhdlFileName%.*}"".sv"

        echo "/home/guangdadong/work/project/G1/g1-arch-evolution/source/sections/SoC/dist/vhd2vl/src/vhd2vl $path > $verilogFileName"
        /home/guangdadong/work/project/G1/g1-arch-evolution/source/sections/SoC/dist/vhd2vl/src/vhd2vl $path > $verilogFileName
      fi
    fi
  done
}

read_dir $1
